package cn.tedu.bonfire.admin.account.service.impl;

import cn.tedu.bonfire.admin.account.dao.persist.repository.IUserAndRoleRepository;
import cn.tedu.bonfire.admin.account.pojo.entity.UserAndRole;
import cn.tedu.bonfire.admin.account.service.IUserAndRoleService;
import cn.tedu.bonfire.admin.account.service.IUserRoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class UserAndRoleServiceImpl implements IUserAndRoleService {

    @Autowired
    private IUserAndRoleRepository userAndRoleRepository;
    @Autowired
    private IUserRoleService userRoleService;


    @Override
    public int insert(UserAndRole userAndRole) {
        return userAndRoleRepository.insert(userAndRole);
    }

    @Override
    public void updateUserRoleById(Long userId,Long roleId) {

        userAndRoleRepository.updateRoleIdByUserId(userId,roleId);

        String roleName = userRoleService.selectRoleNameById(roleId);
        userAndRoleRepository.updateUserDescriptionByUserId(userId,roleName);
    }
}
